package com.example.xm.ui.home.activity.youhome_fragments;

import android.widget.LinearLayout;

import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.xm.R;
import com.example.xm.adapter.HomeAdapter.YouHomeTrendAdapter;
import com.example.xm.base.BaseFragment;
import com.example.xm.bean.HomeBean.HomeYouHomeArticleBean;
import com.example.xm.bean.HomeBean.HomeYouHomeBean;
import com.example.xm.bean.HomeBean.HomeYouHomeExerciseBean;
import com.example.xm.bean.HomeBean.HomeYouHomeSocietyBean;
import com.example.xm.bean.HomeBean.HomeYouHomeTrendBean;
import com.example.xm.interfaces.youhome.IYouHome;
import com.example.xm.presenter.home.YouHomePresenter;

import java.util.ArrayList;

import butterknife.BindView;

public class TrendsFragment extends BaseFragment<IYouHome.Presenter> implements IYouHome.View {

    @BindView(R.id.rlv_trend)
    RecyclerView rlvTrend;
    private ArrayList<HomeYouHomeTrendBean.DataBean.DynamicsBean> list;
    private YouHomeTrendAdapter youHomeTrendAdapter;

    @Override
    protected IYouHome.Presenter initPresenter() {
        return new YouHomePresenter();
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_youhome_trend;
    }

    @Override
    protected void initView() {
        list = new ArrayList<>();
        rlvTrend.setLayoutManager(new LinearLayoutManager(getActivity()));
        rlvTrend.addItemDecoration(new DividerItemDecoration(getActivity(), LinearLayout.VERTICAL));
        youHomeTrendAdapter = new YouHomeTrendAdapter(getActivity(), list);
        rlvTrend.setAdapter(youHomeTrendAdapter);
    }

    @Override
    protected void initData() {
        mPresenter.getTrends();
    }

    @Override
    protected void initListener() {

    }

    @Override
    public void getYouHomeReturn(HomeYouHomeBean result) {

    }

    @Override
    public void getTrends(HomeYouHomeTrendBean result) {
        if (result.getStatus().getStatusCode() == 100){
            list.addAll(result.getData().getDynamics());
            youHomeTrendAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public void getExerciseReturn(HomeYouHomeExerciseBean result) {

    }

    @Override
    public void getSocietyReturn(HomeYouHomeSocietyBean result) {

    }

    @Override
    public void getArticleReturn(HomeYouHomeArticleBean result) {

    }

    @Override
    public void showTips(String tips) {

    }

    @Override
    public void showLoading(int visble) {

    }
}
